#!/bin/bash

BIN=/usr/bin/chromium

Chrome_Default_Cli=" --ignore-gpu-blocklist --no-first-run --password-store=basic --simulate-outdated-no-au='Tue, 31 Dec 2099 23:59:59 GMT' --start-maximized --user-data-dir"

if [[ "$HEADLESS" == "true" ]]; then
    echo "HEADLESS is true"
    Chrome_Default_Cli+=" --headless"
else
    echo "HEADLESS is not true"
fi

if [[ "$REMOTE_DEBUGGING" == "true" ]]; then
    echo "REMOTE_DEBUGGING is true"
    Chrome_Default_Cli+=" --remote-debugging-port=9222 --remote-debugging-address=0.0.0.0"
else
    echo "REMOTE_DEBUGGING is not true"
fi

# Cleanup
if ! pgrep chromium > /dev/null;then
  rm -f $HOME/.config/chromium/Singleton*
fi

# Run normally on privved containers or modified un non priv
if grep -q 'Seccomp:.0' /proc/1/status; then
  ${BIN} ${Chrome_Default_Cli} "$@" > /dev/null 2>&1
else
  ${BIN} ${Chrome_Default_Cli} --test-type "$@" > /dev/null 2>&1
fi